//
//  XMNetwork+find.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/7/2.
//

#import "XMNetwork+find.h"

@implementation XMNetwork (find)

/**
 图文列表
 */
- (void)getPicWordListWithPath:(NSString *)pathStr
                       pageNum:(NSString *)pageNum
                     sessionId:(nonnull NSString *)sessionId
                          city:(nonnull NSString *)city
                       success:(void (^)(id _Nonnull))successBlock
                       failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:pageNum forKey:@"pageNum"];
    [parameters safe_setObject:@"10" forKey:@"pageSize"];
    if (city && city.length > 0) {
        [parameters safe_setObject:city forKey:@"city"];
    }
    [self postDataWithPath:pathStr
                parameters:parameters
                 needToken:NO
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 点赞视频
 */
- (void)videoLikedWithVideoId:(NSString *)videoId
                      success:(void (^)(NSError * _Nonnull))successBlock
                      failure:(void (^)(NSError * _Nonnull))failureblock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:videoId forKey:@"videoId"];
    [self postDataWithPath:videoLikedUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureblock (error);
    }];
}

/**
 图文详情
 */
- (void)getPicwordDetailWithPicwordId:(NSString *)picwordId
                              success:(void (^)(id _Nonnull))successBlock
                              failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSString *path = picwordDetailUrl;
    XMUserModel *userModel = [[XMUserManager shareInstance] getUser];
    if (userModel && userModel.refreshToken.length > 0) {
        path = loginPicwordDetailUrl;
        [parameters safe_setObject:picwordId forKey:@"videoId"];
    }
    else {
        [parameters safe_setObject:picwordId forKey:@"id"];
    }
    [self getDataWithPath:path
               parameters:parameters
                needToken:NO
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 图文评论
 */
- (void)getPicwordCommentWithPicwordId:(NSString *)picwordId
                                  page:(NSString *)page
                               success:(void (^)(id _Nonnull))successBlock
                               failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:picwordId forKey:@"videoId"];
    [parameters safe_setObject:page forKey:@"pageNum"];
    [parameters safe_setObject:@"10" forKey:@"pageSize"];
    [self getDataWithPath:picwordCommentListUrl
               parameters:parameters
                needToken:NO
                  headers:@{}
          showPrograssHUD:NO
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 评论图文
 */
- (void)picwordCommentWithPicwordId:(NSString *)picwordId
                          commentId:(NSString *)commentId
                     picwordContent:(NSString *)contentStr
                       commentLevel:(NSString *)commentLevel
                            success:(void (^)(id _Nonnull))successBlock
                            failure:(void (^)(NSError * _Nonnull))failureBlock{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:picwordId forKey:@"videoId"];
    [parameters safe_setObject:commentId forKey:@"commentId"];
    [parameters safe_setObject:contentStr forKey:@"content"];
    [parameters safe_setObject:commentLevel forKey:@"clevel"];
    [self postDataWithPath:picwordCommentUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 图文点赞
 */
- (void)picwordLikeWithPicwordId:(NSString *)picwordId
                         success:(void (^)(id _Nonnull))successBlock
                         failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:picwordId forKey:@"videoId"];
    [self postDataWithPath:picwordLikeUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 图文评论点赞
 */
- (void)picwordCommentLikeWithCommentId:(NSString *)commentId
                                success:(void (^)(id _Nonnull))successBlock
                                failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:commentId forKey:@"videoCommentId"];
    [self postDataWithPath:picwordCommentLikeUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
           showPrograssHUD:NO
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 多张图片上传
 */
- (void)imgUploadWithImg:(NSArray *)imgArr
               directory:(NSString *)directory
                 success:(void (^)(id _Nonnull))successBlock
                 failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:directory forKey:@"directory"];
    [self upLoadImgsWithPath:uploadImgsUrl
                  parameters:parameters
                         img:imgArr
                     success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 发布图文
 */
- (void)picwordPublishWithParameters:(NSMutableDictionary *)parameters
                             success:(void (^)(id _Nonnull))successBlock
                             failure:(void (^)(NSError * _Nonnull))failureBlock {
    [self postDataWithPath:picwordPublishUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 图文搜索
 */
- (void)picwordSearchWithPage:(NSString *)page
                          key:(NSString *)key
                     timeType:(NSString *)timeType
                 isByTimesort:(NSString *)isByTimesort
                      success:(void (^)(id _Nonnull))successBlock
                      failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:page forKey:@"pageNum"];
    [parameters safe_setObject:@"10" forKey:@"pageSize"];
    [parameters safe_setObject:key forKey:@"key"];
    [parameters safe_setObject:timeType forKey:@"timeType"];
    [parameters safe_setObject:isByTimesort forKey:@"isByTimeSort"];
    [self postDataWithPath:picwordSearchUrl
                parameters:parameters
                 needToken:NO
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 用户搜索
 */
- (void)findUserSearchWithSearchKey:(NSString *)searchKey
                               page:(NSString *)page
                            success:(void (^)(id _Nonnull))successBlock
                            failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:searchKey forKey:@"key"];
    [parameters safe_setObject:page forKey:@"pageNum"];
    [parameters safe_setObject:@"10" forKey:@"pageSize"];
    [self postDataWithPath:findUserSearchUrl
                parameters:parameters
                 needToken:NO
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

@end
